package Thread;
//一个线程在进行加锁操作后在进行加速操操做;
//观察情况发现：在同一个线程的情况下：无论加多少锁后都对结果没有影响；
//进而得出：java的可重入特性；解决了上述的问题；
class Count2{
     public static int count=0;
     public synchronized void add(){
         count++;
     }
     public int getCount(){
         return count;
     }
}
public class Demo19 {
    public static void main(String[] args) throws InterruptedException {
        Object locker=new Object();
        Count2 count2=new Count2();
        Thread t1=new Thread(()->{
            for(int i=0;i<50000;i++) {
                synchronized (locker) {
                    count2.add();
                }
            }
        });
        Thread t2=new Thread(()->{
            for(int i=0;i<50000;i++) {
                synchronized (locker) {
                    count2.add();
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count="+count2.getCount());
    }



}
